<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@include file="common/indexhead.jsp"%>
<%@include file="common/tag.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/mystyle/zTreeStyle/css/demo.css"
	type="text/css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/mystyle/zTreeStyle/css/zTreeStyle.css"
	type="text/css">
<script
	src="${pageContext.request.contextPath}/assets/vendor/jquery/jquery.min.js"></script>
<script
	src="${pageContext.request.contextPath}/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/mystyle/zTreeStyle/js/jquery.ztree.core.js"></script>
<script src="${pageContext.request.contextPath}/mystyle/js/userclick.js"
	type="text/javascript" charset="utf-8"></script>
<!-- <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/> -->

</head>

<body>
<table class="table table-hover"  style="width:100%">
			<thead>
				<tr>
					<th>部门名称</th>
					<th>上级部门ID</th>
					<th>部门编号</th>
					<th>创建时间</th>
					<th>详情</th>
					<th class="mydelete">删除</th>
					</tr>
			</thead>
			<tbody>
	<c:forEach var="dept" items="${deptlist}">
		<tr>
			<td>${dept.deptName}</td>
			<td>${dept.topId}</td>
			<td>${dept.deptNumber}</td>
			<td><fmt:formatDate value="${dept.createTime}"
					pattern="yyyy-MM-dd" /></td>
			<td style="width:10px"><a class="btn btn-info"
				href="/dept/${dept.deptId}/detail" target="_blank">详情</a></td>
			<td class="mydelete" style="width:10px"><a class="btn btn-danger"
				onclick="tijiao('${dept.deptId}','${dept.topId}')" >删除</a></td>
		</tr>
	</c:forEach>
		 
				<%-- onclick="window.parent.changeIframe('/user/${us.userId}/detail')"   --%>
			</tbody>
		</table>
		<div style="margin-top:-30px" id="resultlist" >
	
		</div>
	<!-- 弹出框重写 -->
<div id="ycf-alert" class="modal">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
            <h5 class="modal-title"><i class="fa fa-exclamation-circle"></i> [Title]</h5>
          </div>
          <div class="modal-body small">
            <p>[Message]</p>
          </div>
          <div class="modal-footer" >
            <button type="button" class="btn btn-primary ok" data-dismiss="modal">[BtnOk]</button>
            <button type="button" class="btn btn-default cancel" data-dismiss="modal">[BtnCancel]</button>
          </div>
        </div>
      </div>
    </div>
<!-- 弹出框重写end -->
</body>
<script type="text/javascript">

fenye(${pb.currentPage},${pb.totalPages},${pb.totalRecords},${pb.pagesize},"/dept/deptlist");
</script>
<script type="text/javascript">
function tijiao(deptId,topId) {
Modal.confirm({
    msg: "是否删除该部门？"
}).on(function(e) {
    $.ajax({
        type: "get",
        url: yongan.URL.deptDelete(deptId),
        dataType: "json",
        data: {},
        success: function(data) {
            if (data['success']) {
                Modal.alert({
                    msg: data['data']['stateinfo'],
                    title: '执行结果',
                    btnok: '确定',
                    btncl: '取消'
                }).on(function(e) {
                	window.location.reload();
                });
            }else{
            	Modal.alert({
                    msg: data['data']['stateinfo'],
                    title: '执行结果',
                    btnok: '确定',
                    btncl: '取消'
                }).on(function(e) {
                	//window.location.reload();
                });
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
            alert(textStatus);
            alert(errorThrown);
        }
    });
});
}
$(function() {
if("<%=request.getSession().getAttribute("userid")%>"!="admin"){
	$(".mydelete").hide();
}
	window.Modal = function() {
	    var reg = new RegExp("\\[([^\\[\\]]*?)\\]", 'igm');
	    var alr = $("#ycf-alert");
	    var ahtml = alr.html();

	    //关闭时恢复 modal html 原样，供下次调用时 replace 用
	    //var _init = function () {
	    //alr.on("hidden.bs.modal", function (e) {
	    //  $(this).html(ahtml);
	    //});
	    //}();
	    /* html 复原不在 _init() 里面做了，重复调用时会有问题，直接在 _alert/_confirm 里面做 */

	    var _alert = function(options) {
	        alr.html(ahtml); // 复原
	        alr.find('.ok').removeClass('btn-success').addClass('btn-primary');
	        alr.find('.cancel').hide();
	        _dialog(options);

	        return {
	            on: function(callback) {
	                if (callback && callback instanceof Function) {
	                    alr.find('.ok').click(function() {
	                        callback(true)
	                    });
	                }
	            }
	        };
	    };

	    var _confirm = function(options) {
	        alr.html(ahtml); // 复原
	        alr.find('.ok').removeClass('btn-primary').addClass('btn-success');
	        alr.find('.cancel').show();
	        _dialog(options);

	        return {
	            on: function(callback) {
	                if (callback && callback instanceof Function) {
	                    alr.find('.ok').click(function() {
	                        callback(true)
	                    });

	                }
	            }
	        };
	    };

	    var _dialog = function(options) {
	        var ops = {
	            msg: "提示内容",
	            title: "操作提示",
	            btnok: "确定",
	            btncl: "取消"
	        };

	        $.extend(ops, options);

	      //  console.log(alr);

	        var html = alr.html().replace(reg,
	        function(node, key) {
	            return {
	                Title: ops.title,
	                Message: ops.msg,
	                BtnOk: ops.btnok,
	                BtnCancel: ops.btncl
	            } [key];
	        });

	        alr.html(html);
	        alr.modal({
	            width: 500,
	            backdrop: 'static'
	        });
	    }

	    return {
	        alert: _alert,
	        confirm: _confirm
	    }

	} ();
	});





</script>
</html>
